package com.offer;

public class Test16 {

    public double myPow(double x, int n) {
        long N = n;
        return N >= 0 ? quickMul(x, N) : 1.0 / quickMul(x, -N);

    }

    private double quickMul(double x, long n) {
        if (n <= 0) {
            return 1;
        }

        double tempResult = quickMul(x, n / 2);

        return n % 2 == 1 ? x * tempResult * tempResult : tempResult * tempResult;
    }


    public static void main(String[] args) {
        Test16 test16 = new Test16();
        double result = test16.myPow(2, -2147483648);
        System.out.println(result);
    }

}
